package com.LostAndFound.service;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import com.LostAndFound.dao.SuccessRecordListDao;
import com.LostAndFound.utils.DataSourceUtils;

public class SuccessRecordListService {
	SuccessRecordListDao dao = new SuccessRecordListDao();

	public int getTotalRecordForEasyUI(String cid, String whatFlag) {
		int total = 0;
		try {
			total = dao.getTotalRecordForEasyUI(cid,whatFlag);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return total;
	}

	public List<Map<String, Object>> findAllSuccessRecordsForEasyUI(int pageNumber, int pageSize, String cid,
			String whatFlag) {
		List<Map<String, Object>> mapList = null;
		int startIndex = (pageNumber-1)*pageSize;
		try {
			mapList = dao.findAllSuccessRecordsForEasyUI(startIndex,pageSize,cid,whatFlag);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return mapList;
	}

	// 删除成功记录，要一起删除foundarticle和article中的
	public boolean handleDeleteSuccessRecordForEasyUI(String aid) {
		boolean success = false;
		try {
			DataSourceUtils.startTransaction();
			dao.handleDeleteAtFoundArticleForEasyUI(aid);
			dao.handleDeleteAtArticleForEasyUI(aid);
			success = true;
		} catch (SQLException e) {
			try {
				DataSourceUtils.rollback();
			} catch (SQLException e1) {
				e1.printStackTrace();
			}
		} finally {
			try {
				DataSourceUtils.commitAndRelease();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return success;
	}
}
